package cn.zurish.cloud.security;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;

public class SpELExample {
    public static void main(String[] args) {
        ExpressionParser parser = new SpelExpressionParser();

        // 动态数组内容和目标字符串
        String[] arrayElements = {"apple", "banana", "cherry", "date", "ling"};
        String target = "ling";

        // 构建动态表达式
        String elements = String.join(",", java.util.Arrays.stream(arrayElements).map(s -> "'" + s + "'").toArray(String[]::new));
        String expressionStr = "T(java.util.Arrays).asList(" + elements + ").contains('" + target + "')";

        System.out.println("Expression: " + expressionStr);

        // 执行表达式
        Boolean result = parser.parseExpression(expressionStr).getValue(Boolean.class);
        System.out.println("Result: " + result);
    }
}
